<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@ page import="com.huawei.iptvmw.epg.bean.MetaData" %>
<%@ page import="com.huawei.iptvmw.epg.bean.ServiceHelpHWCTC" %>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<title>语音1</title>
<%
    String tempswitch="on";//on--开启页面跳转  off--关闭   直接去首页index.jsp
    String path = request.getRequestURI().substring(0,request.getRequestURI().lastIndexOf("/")+1);
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
    //跳转类型：live--直播  vod--点播  tvod 回放
    String yuyintype=request.getParameter("yuyintype")==null? "-1":(String)request.getParameter("yuyintype");
    //直播
    String chanNum=request.getParameter("channelIndex")==null? "-1":(String)request.getParameter("channelIndex");
    //点播
    String foreignid=request.getParameter("foreignid")==null? "-1":(String)request.getParameter("foreignid");
    String gotoType=request.getParameter("gotoType")==null? "1":(String)request.getParameter("gotoType");//跳转类型（1、跳到详情页）
    String returnUrl=request.getParameter("returnUrl");
    String curdate=request.getParameter("curdate")==null? "-1":(String)request.getParameter("curdate");
    if(returnUrl==null){
        returnUrl=basePath+"page/index.html";
    }
    String urltemp="index.html";
    String error="";
    String channelCODE="";
    String probefrom = "&probefrom=voiceremote";
    HashMap chanInfo=null;
    int isJGVod = 0; // 是否是极光节目
    String jgUrl = ""; // 极光跳转详情页地址
    if(yuyintype.equals("channel")){//直播
        urltemp=basePath+"page/chanPlayer.html?channelIndex="+chanNum;
    }
    else if(yuyintype.equals("vod")){//点播
        urltemp=basePath+"page/vodDetail.jsp?foreignid="+foreignid;
        MetaData metadata = new MetaData(request);
        HashMap vodInfo = metadata.getContentDetailInfoByForeignSN(foreignid, 0);
        if (vodInfo != null && vodInfo.get("VODID") != null) {
            int programCode = (Integer)vodInfo.get("VODID");
            if (programCode != -1) {
                if (vodInfo.get("TAGARRAY") != null) {
                    String[] tagarrays = (String[]) vodInfo.get("TAGARRAY");
                    if (tagarrays != null) {
                        StringBuffer allTagarrayss = new StringBuffer();
                        for (String str1 : tagarrays) {
                            allTagarrayss.append("," + str1.trim());
                        }
                        String tags = allTagarrayss.toString();
                        if(tags.indexOf("腾讯极光") > -1) {
                            isJGVod = 1;

                            int resprogramType = Integer.parseInt(vodInfo.get("ISSITCOM").toString());
                            if (resprogramType == 0) {
                                jgUrl = "detailNew.html";
                            }
                            else if(resprogramType == 1) {
                                jgUrl = "detailMuchNew.html";
                                if (vodInfo.get("TYPE") != null) {
                                    String detailTYPE = vodInfo.get("TYPE").toString();
                                    if (detailTYPE != null && !detailTYPE.equals("")) {
                                        if("综艺".equals(detailTYPE) || "纪实".equals(detailTYPE) || "体育".equals(detailTYPE) || "纪录片".equals(detailTYPE) || "娱乐".equals(detailTYPE)) {
                                            jgUrl = "detailVNew.html";
                                        }
                                    }
                                }
                            }

                            jgUrl += "?programCode=" + programCode;
                        }
                    }
                }
            }
        }
    }
    else if(yuyintype.equals("tvod")){//回放 播放页面
        if(!"-1".equals(foreignid)){
            try{
                MetaData metadata = new MetaData(request);
                HashMap info = metadata.getContentDetailInfoByForeignSN(foreignid, 300);
                if (info != null&&info.get("channelCODE")!=null) {
                    String code=info.get("PROGID").toString();
                    String startTime=info.get("STARTTIME").toString();
                    String endTime=info.get("ENDTIME").toString();
                    ServiceHelpHWCTC serviceHelphwctc = new ServiceHelpHWCTC(request);
                    String playUrl = serviceHelphwctc.getTriggerPlayUrlHWCTC(4,Integer.parseInt(code),Integer.parseInt(code),startTime,endTime,"0","0","300");
                    if(playUrl != null && playUrl.length() > 0){
                        int tmpPosition = playUrl.indexOf("rtsp");
                        int httpPosition = playUrl.indexOf("http");
                        if(-1 != tmpPosition){
                            playUrl = playUrl.substring(tmpPosition,playUrl.length());
                            if(playUrl.indexOf(".mp4") != -1){
                                playUrl = playUrl.replaceFirst("rtsp","http");
                            }
                        }else if(-1 != httpPosition){
                            playUrl = playUrl.substring(httpPosition,playUrl.length());
                        }
                    }
                    channelCODE=info.get("channelCODE").toString();
                    String date=info.get("STARTTIME").toString().substring(0,8);
                    chanInfo = metadata.getContentDetailInfoByForeignSN(channelCODE,1);
                    if(chanInfo!=null){
                        chanNum=chanInfo.get("CHANNELINDEX").toString();
                    }
                    urltemp=basePath+"page/chanPlayer.html?channelIndex="+chanNum+
                    "&code="+code+"&date="+date+"&u="+URLEncoder.encode(playUrl, "UTF-8");
                }
            }
            catch(Exception e){
                    //error=e.toString();
            }
        }
        else if(!"-1".equals(curdate)){
            Date now = new Date();
            SimpleDateFormat curday = new SimpleDateFormat("yyyy");
            curdate = curday.format(now)+curdate;
            urltemp=basePath+"page/chanPlayer.html?channelIndex="+chanNum+"&date="+curdate;
        }
    }

    if(isJGVod == 1) {
        urltemp = basePath + "page/apkJump.html?type=1&from=1&url=" + URLEncoder.encode(jgUrl, "UTF-8") + "&returnUrl=" + URLEncoder.encode(returnUrl, "UTF-8");
    }
    else {
        if(urltemp.indexOf("?")>-1){
            urltemp += "&returnUrl="+URLEncoder.encode(returnUrl, "UTF-8");
        }
        else{
            urltemp += "?returnUrl="+URLEncoder.encode(returnUrl, "UTF-8");
        }

        // 外部来源
        urltemp += probefrom;
        if(urltemp.indexOf("chanPlayer.html")>-1){
            urltemp += "&probefrompage=livefs";
        }
        // 外部来源结束
        if(!tempswitch.equals("on")){
            urltemp=basePath+"page/index.html";
        }
    }
    String jumpurl=basePath+"page/layout.html?url=" + URLEncoder.encode(urltemp, "UTF-8");
    response.sendRedirect(jumpurl);
%>
<!-- <script>
    var tempe="< %=error%>";
    var url="< %=jumpurl%>";
    var channelCODE="< %=channelCODE%>";
    var chanInfo="< %=chanInfo%>";
</script> -->
